// Copyright Leonid Shlyapnikov 2011
// Distributed under the GNU Lesser General Public License http://www.gnu.org/licenses/lgpl.html
//    author: Leonid Shlyapnikov, created on: Jun 11, 2011

#include <boost/test/test_tools.hpp>
#include <boost/preprocessor/seq/push_back.hpp>

#include <stdint.h>
#include <limits>

#include "../../main/fixparser/define_msg_macro.h"

#define TEST_MSG_TAGS \
    (8)(9)(34)
    /**/

#define HEADER \
    (8)(9)(35)(49)(56)(34)(52) \
    /**/

#define MSG_D \
    HEADER (333)(444)(555)(666) \
    /**/

FIXPARSER_DEFINE_MSG(NewOrderSingle, "D", HEADER (333)(444)(555)(666));

size_t tagToIndex_Base0(size_t tagNumber) {
//    switch (tagNumber) {
//    case 8:
//        return base;
//    case 9:
//        return base + 1;
//    case 34:
//        return base + 2;
//    default:
//        return -1;
//    }

//    switch (tagNumber) {
//    BOOST_PP_SEQ_FOR_EACH_I(FIXPARSER_TAG_TO_INDEX_CASE, 0, TEST_MSG_TAGS)
//    default:
//        return -1;
//    }

    FIXPARSER_DEFINE_TAG_TO_INDEX(tagNumber, 0, TEST_MSG_TAGS);
}

size_t tagToIndex_Base10(size_t tagNumber) {
    FIXPARSER_DEFINE_TAG_TO_INDEX(tagNumber, 10, (8)(9)(34));
}

void define_msg_macro_tag_hash_test() {
    BOOST_CHECK_EQUAL(0, tagToIndex_Base0(8));
    BOOST_CHECK_EQUAL(1, tagToIndex_Base0(9));
    BOOST_CHECK_EQUAL(2, tagToIndex_Base0(34));
    BOOST_CHECK_EQUAL(-1, tagToIndex_Base0(10));
    BOOST_CHECK_EQUAL(-1, tagToIndex_Base0(123));

    BOOST_CHECK_EQUAL(10, tagToIndex_Base10(8));
    BOOST_CHECK_EQUAL(11, tagToIndex_Base10(9));
    BOOST_CHECK_EQUAL(12, tagToIndex_Base10(34));
    BOOST_CHECK_EQUAL(-1, tagToIndex_Base10(10));
    BOOST_CHECK_EQUAL(-1, tagToIndex_Base10(123));

    BOOST_CHECK_EQUAL(0, NewOrderSingle::tagToIndex(8));
    BOOST_CHECK_EQUAL(1, NewOrderSingle::tagToIndex(9));
    BOOST_CHECK_EQUAL(5, NewOrderSingle::tagToIndex(34));
    BOOST_CHECK_EQUAL(7, NewOrderSingle::tagToIndex(333));
    BOOST_CHECK_EQUAL(-1, NewOrderSingle::tagToIndex(10));
    BOOST_CHECK_EQUAL(-1, NewOrderSingle::tagToIndex(123));
    BOOST_CHECK_EQUAL(11, NewOrderSingle::numberOfIndexedTags());
    BOOST_CHECK_EQUAL("D", NewOrderSingle::type());

    BOOST_CHECK_EQUAL(true, NewOrderSingle::isInvalidIndex(std::numeric_limits<size_t>::max()));

//    BOOST_MESSAGE("invalid index: "<< NewOrderSingle::invalidIndex());
//    BOOST_MESSAGE("invalid index: "<< (int) (NewOrderSingle::invalidIndex()));
}


